package com.then.component.login.applike;

import android.app.Activity;
import android.support.v4.app.Fragment;

import com.luojilab.component.componentlib.applicationlike.IApplicationLike;
import com.luojilab.component.componentlib.router.Router;
import com.luojilab.component.componentlib.router.ui.UIRouter;
import com.luojilab.componentservice.app.DaggerComponentService;
import com.then.architecture.InjectorMap;
import com.then.architecture.di.DaggerComponent;
import com.then.component.login.BuildConfig;
import com.then.component.login.di.AppLikeComponent;
import com.then.component.login.di.LoginModule;
import com.then.component.login.di

        .DaggerAppLikeComponent;

import javax.inject.Inject;

import dagger.android.AndroidInjector;
import dagger.android.DispatchingAndroidInjector;
import dagger.android.HasActivityInjector;
import dagger.android.support.HasSupportFragmentInjector;

/**
 * Created by 42524 on 2018/1/11.
 */

public class LoginAppLike implements IApplicationLike, HasActivityInjector {


    UIRouter uiRouter = UIRouter.getInstance();

    @Inject
    DispatchingAndroidInjector<Activity> mActivityInjector;

    @Inject
    InjectorMap injectorMap;

  /*  @Inject
    DispatchingAndroidInjector<Fragment> mFragmentInjector;*/

    AppLikeComponent appLikeComponent;

    @Override
    public void onCreate() {
        uiRouter.registerUI("login");
        Object o = Router.getInstance().getService(DaggerComponentService.class.getSimpleName());
        if (o != null) {
            DaggerComponent component = (DaggerComponent) o;
            appLikeComponent = DaggerAppLikeComponent.builder().daggerComponent(component).loginModule(new LoginModule(this)).build();
            appLikeComponent.inject(this);
            injectorMap.putActivityInjector(BuildConfig.APPLICATION_ID,this);
        }

    }

    @Override
    public void onStop() {
        uiRouter.unregisterUI("login");
    }

    @Override
    public AndroidInjector<Activity> activityInjector() {
        return mActivityInjector;
    }

    /*@Override
    public AndroidInjector<Fragment> supportFragmentInjector() {
        return mFragmentInjector;
    }*/
}
